package com.googlecode.connectlet.machine.provider;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.Provider;

import com.googlecode.connectlet.crypto.random.RC4PrngCipher;
import com.googlecode.connectlet.machine.provider.key.MachineKeyPairGenerator;
import com.googlecode.connectlet.machine.provider.key.MachineKeyStore;
import com.googlecode.connectlet.machine.provider.key.MachinePrivateKeyFactory;
import com.googlecode.connectlet.machine.provider.param.MachineParameterGenerator;
import com.googlecode.connectlet.machine.provider.param.MachineParameters;
import com.googlecode.connectlet.machine.provider.signature.MachineMD5withRSA;

public final class MachineProvider extends Provider {
	private static final long serialVersionUID = 1L;

	private static volatile MachineProvider instance = null;

	public static MachineProvider getInstance() {
		if (instance == null) {
			synchronized (RC4PrngCipher.class) {
				if (instance == null) {
					instance = new MachineProvider();
				}
			}
		}
		return instance;
	}

	private MachineProvider() {
		super("MachineProvider", 1.0, "MachineProvider");
		AccessController.doPrivileged(new PrivilegedAction<Object>() {
			@Override
			public Object run() {
				put("AlgorithmParameterGenerator.Machine", MachineParameterGenerator.class.getName());
				put("AlgorithmParameters.Machine", MachineParameters.class.getName());
				put("Signature.MD5withRSA", MachineMD5withRSA.class.getName());
				put("KeyPairGenerator.RSA", MachineKeyPairGenerator.class.getName());
				put("KeyFactory.RSA", MachinePrivateKeyFactory.class.getName());
				put("KeyStore.Machine", MachineKeyStore.class.getName());
				return null;
			}
		});
	}
}